﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PortalCurriculo.WebUI.Helpers
{
    public class WebHelper
    {
        public static void ShowMessageBox(string message, ref UpdatePanel updatePanel)
        {
            ScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), Guid.NewGuid().ToString(),
                                                string.Format("alert('{0}');", message), true);
        }

        public static void FillDropDownList(DropDownList dropDownList, object dataSource, bool selectOption)
        {
            dropDownList.DataTextField = "Descricao";
            dropDownList.DataValueField = "Id";

            dropDownList.Items.Clear();

            if (dataSource != null)
            {
                dropDownList.DataSource = dataSource;
                dropDownList.DataBind();
            }

            if (!selectOption) return;

            string translated = Util.Translation.Translator.TranslateMessage(Messages.Selecione, dropDownList.Page.AppRelativeVirtualPath);
            dropDownList.Items.Insert(0, new ListItem(translated, "-1"));
        }

        public static void FillDropDownList(DropDownList dropDownList, object dataSource, bool selectOption, string dataTextField)
        {
            dropDownList.DataTextField = dataTextField;
            dropDownList.DataValueField = "Id";

            dropDownList.Items.Clear();

            if (dataSource != null)
            {
                dropDownList.DataSource = dataSource;
                dropDownList.DataBind();
            }

            if (!selectOption) return;

            string translated = Util.Translation.Translator.TranslateMessage(Messages.Selecione, dropDownList.Page.AppRelativeVirtualPath);
            dropDownList.Items.Insert(0, new ListItem(translated, "-1"));
        }
    }
}